﻿using System;
using jade.content.onto;
using jade.content.schema;
using log4net;

namespace GatewayUtil.agents.ontology
{
    public class DynamicWSOntology : Ontology
    {

        private static readonly ILog log = LogManager.GetLogger(typeof(DynamicWSOntology));
        /**
         * the name of ontology
         **/
        public static String ONTOLOGY_NAME = "DynamicWSOntology";

        /**
         * vocabulary
         **/
        public static String WS_REQUEST = "WSRequest";
        public static String WS_RESPONSE = "WSResponse";
        public static String SERVICE_URL = "ServiceURL";
        public static String METHOD_NAME = "MethodName";
        public static String SERVICE_NAME = "ServiceName";
        public static String ARGUMENTS = "Arguments";
        public static String WS_RESPONSE_OBJECT = "ResponseObject";


        private static Ontology theInstance = new DynamicWSOntology();

        public static Ontology getInstance()
        {
            return theInstance;
        }

        public DynamicWSOntology()
            : base(ONTOLOGY_NAME, new Ontology[] { BasicOntology.getInstance(), SerializableOntology.getInstance() }, new BCReflectiveIntrospector())
        {
            try
            {
                add(new AgentActionSchema(WS_REQUEST), java.lang.Class.forName("GatewayUtil.agents.ontology." + WS_REQUEST));
                add(new ConceptSchema(WS_RESPONSE), java.lang.Class.forName("GatewayUtil.agents.ontology." + WS_RESPONSE));

                AgentActionSchema request = (AgentActionSchema)getSchema(WS_REQUEST);
                request.add(METHOD_NAME, (PrimitiveSchema)getSchema(BasicOntology.STRING));
                request.add(SERVICE_URL, (PrimitiveSchema)getSchema(BasicOntology.STRING));
                request.add(SERVICE_NAME, (PrimitiveSchema)getSchema(BasicOntology.STRING));
                request.add(ARGUMENTS, (TermSchema)TermSchema.getBaseSchema(), 0, ObjectSchema.UNLIMITED);
                request.setResult((ConceptSchema)getSchema(WS_RESPONSE));

                ConceptSchema response = (ConceptSchema)getSchema(WS_RESPONSE);
                response.add(WS_RESPONSE_OBJECT, (TermSchema)TermSchema.getBaseSchema());

            }
            catch (Exception e)
            {                
                log.Error(e);
                throw e;
            }
        }

    }
}
